Patch from Stefan Gehn to implement copying from a pixmap, bug #348493.
authorRichard Hult <richard@imendio.com>
Thu, 30 Aug 2007 07:57:25 +0000 (07:57 +0000)
committerRichard Hult <rhult@src.gnome.org>
Thu, 30 Aug 2007 07:57:25 +0000 (07:57 +0000)
2007-08-30  Richard Hult  <richard@imendio.com>

* gdk/quartz/gdkimage-quartz.c: (_gdk_quartz_image_copy_to_image):
Patch from Stefan Gehn to implement copying from a pixmap, bug
#348493.

svn path=/trunk/; revision=18702

ChangeLog
gdk/quartz/gdkimage-quartz.c

index d2d1a02805756a4a447c835857e6d62c2a5b092e..945dd498d54e18b8a466cf210979d407c5ea1dc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-30  Richard Hult  <richard@imendio.com>
+
+       * gdk/quartz/gdkimage-quartz.c: (_gdk_quartz_image_copy_to_image):
+       Patch from Stefan Gehn to implement copying from a pixmap, bug
+       #348493.
+
 2007-08-29  Kristian Rietveld  <kris@imendio.com>
 
        * gtk/gtksettings.c: lower the default timeout values for
index ed10d8abc8685624ceacacb055a61856931c4892..1d5092d32bfc9c4d89579c9b643c70c57217d4fa 100644 (file)
@@ -49,7 +49,83 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable,
   
   if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable))
     {
-      g_warning ("Copying a pixmap to an image is not implemented yet.");
+      GdkPixmapImplQuartz *pix_impl;
+      gint bytes_per_row;
+      guchar *data;
+      int x, y;
+
+      pix_impl = GDK_PIXMAP_IMPL_QUARTZ (drawable);
+      data = (guchar *)(pix_impl->data);
+
+      if (src_x + width > pix_impl->width || src_y + height > pix_impl->height)
+       {
+          g_warning ("Out of bounds copy-area for pixmap -> image conversion\n");
+          return image;
+        }
+
+      switch (gdk_drawable_get_depth (drawable))
+        {
+        case 24:
+          bytes_per_row = pix_impl->width * 4;
+          for (y = 0; y < height; y++)
+            {
+              guchar *src = data + ((y + src_y) * bytes_per_row) + (src_x * 4);
+
+              for (x = 0; x < width; x++)
+                {
+                  gint32 pixel;
+         
+                  /* RGB24, 4 bytes per pixel, skip first. */
+                  pixel = src[0] << 16 | src[1] << 8 | src[2];
+                  src += 4;
+
+                  gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
+                }
+            }
+          break;
+
+        case 32:
+          bytes_per_row = pix_impl->width * 4;
+          for (y = 0; y < height; y++)
+            {
+              guchar *src = data + ((y + src_y) * bytes_per_row) + (src_x * 4);
+
+              for (x = 0; x < width; x++)
+                {
+                  gint32 pixel;
+         
+                  /* ARGB32, 4 bytes per pixel. */
+                  pixel = src[0] << 24 | src[1] << 16 | src[2] << 8 | src[3];
+                  src += 4;
+
+                  gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
+                }
+            }
+          break;
+
+        case 1: /* TODO: optimize */
+          bytes_per_row = pix_impl->width;
+          for (y = 0; y < height; y++)
+            {
+              guchar *src = data + ((y + src_y) * bytes_per_row) + src_x;
+
+              for (x = 0; x < width; x++)
+                {
+                  gint32 pixel;
+         
+                  /* 8 bits */
+                  pixel = src[0];
+                  src++;
+
+                  gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
+                }
+            }
+          break;
+
+        default:
+          g_warning ("Unsupported bit depth %d\n", gdk_drawable_get_depth (drawable));
+          return image;
+        }
     }
   else if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
     {